<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-pet__petsend}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.petName" placeholder="宠物名字" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
        style="width: 100%">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column label="照片" header-align="center" align="center" width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.imageUrlSize === 0" size="small" type="danger">暂无图片</el-tag>
            <el-image v-else style="width: 80px; height: 80px" :src="scope.row.imageUrlList[0]"
              :preview-src-list="scope.row.imageUrlList"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="petName" label="宠物名字" header-align="center" align="center"></el-table-column>
        <el-table-column prop="petAge" label="宠物年龄" header-align="center" align="center"></el-table-column>
        <el-table-column prop="petGender" label="性别" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petGender === 0" size="small" type="primary">公</el-tag>
            <el-tag v-if="scope.row.petGender === 1" size="small" type="success">母</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petBreed" label="宠物品种" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petBreed === 0" size="small" type="primary">狗狗</el-tag>
            <el-tag v-if="scope.row.petBreed === 1" size="small" type="success">猫猫</el-tag>
            <el-tag v-if="scope.row.petBreed === 2" size="small" type="info">其他</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petVaccine" label="是否注射疫苗" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petVaccine === 0" size="small" type="danger">否</el-tag>
            <el-tag v-if="scope.row.petVaccine === 1" size="small" type="success">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petNeuter" label="是否绝育" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petNeuter === 0" size="small" type="danger">否</el-tag>
            <el-tag v-if="scope.row.petNeuter === 1" size="small" type="success">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petInsect" label="是否驱虫" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petInsect === 0" size="small" type="danger">否</el-tag>
            <el-tag v-if="scope.row.petInsect === 1" size="small" type="success">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petStatus" label="领养状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petStatus === 0" size="small" type="danger">待领养</el-tag>
            <el-tag v-if="scope.row.petStatus === 1" size="small" type="success">已领养</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="sendConditions" label="领养条件" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="showConditions(scope.row.sendConditionNameList)">查看条件</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述信息" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="showDescription(scope.row.description)">查看描述</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" size="small" type="warning">待审核</el-tag>
            <el-tag v-if="scope.row.status === 1" size="small" type="success">审核通过</el-tag>
            <el-tag v-if="scope.row.status === 2" size="small" type="danger">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="审核" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="examine(scope.row.id, 1)">通过</el-button>
            <el-button type="text" size="small" @click="examine(scope.row.id, 2)">未通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
    <el-dialog title="宠物领养条件" :visible.sync="dialogVisible" width="30%">
      <div class="show_conditions">
        <div v-for="(item, index) in showConditionsData" :key="index" style="margin-bottom: 5px; margin-right: 5px">
          <el-tag size="small" type="info">{{ item }}</el-tag>
        </div>
      </div>
    </el-dialog>
    <el-dialog title="宠物描述信息" :visible.sync="desDialogVisible" width="30%">
      <p>{{ showDescriptionData }}</p>
    </el-dialog>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/pet/petsend/page",
        getDataListIsPage: true,
        deleteURL: "/pet/petsend",
        deleteIsBatch: true,
      },
      dataForm: {
        petName: "",
      },
      showConditionsData: {},
      dialogVisible: false,
      showDescriptionData: "",
      desDialogVisible: false,
    };
  },
  components: {
  
  },
  methods: {
    // 展示领养条件信息
    showConditions(item) {
      console.log(item);
      this.dialogVisible = true;
      this.showConditionsData = item;
    },
    // 展示领养描述信息
    showDescription(item) {
      console.log(item);
      this.desDialogVisible = true;
      this.showDescriptionData = item;
    },
    // 审核接口
    examine(id, status) {
      this.$http
        .put("/pet/petsend", {
          id: id,
          status: status
        })
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.$message({
              message: "审核提交成功！",
              type: "success",
            });
            this.query();
          } else {
            this.$message.error("审核提交失败！");
          }
        });
    }
  },
};
</script>

<style>
.show_conditions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  width: 80%;
}
</style>